package com.wlstock.funi.utils;

import android.content.Context;

import com.wlstock.funi.model.OperateModel;
import com.wlstock.funi.model.OperateTrackSetModel;

import static android.R.attr.value;
import static com.tencent.bugly.crashreport.crash.c.f;

public class TradeSetUtils {
//	public final static String BUY_OFFSET =   "BUY_OFFSET";
//	public final static String SAILE_OFFSET = "SAILE_OFFSET";
	
	public final static String LOSE_OFFSET =  "LOSE_OFFSET";
	public final static String WIN_OFFSET  =  "WIN_OFFSET";
	
	public final static String TRADE_TYPE_BUY_OFFSET = "TRADE_TYPE_BUY_OFFSET";
	public final static String TRADE_TYPE_SAILE_OFFSET = "TRADE_TYPE_SAILE_OFFSET";
	public final static String TRADE_MONEY = "TRADE_MONEY";
	public final static String TRADE_IS_BUY_TARCK = "TRADE_IS_BUY_TARCK";
	public final static String TRADE_IS_SAILE_TARCK = "TRADE_IS_SAILE_TARCK";
	
	
//	public final static String IS_SPECIFIC_ON = "IS_SPECIFIC_ON";
	/**
	 * 是否语音播报
	 */
	public final static String IS_VOICE_ON =   "IS_VOICE_ON";
	/**
	 * 语音播放间隔
	 */
	private static final String VOICE_DIS = "VOICE_DIS";
	
	private static final String EXPTEC_POSITION  = "EXPECTED_POSITION";
	
	
	public static float getLossOffset(Context mContext, String lossType){
		float value = GlobalIndexHelper.getInstance(mContext).getBuyPercent();
		if (lossType.equals(LOSE_OFFSET)) {
			float loseOffset = SharePreferenceUtils.getFloatSP(mContext, lossType, -0.1f);
			if (value == -1){
				return loseOffset;
			}
			else{
				loseOffset = loseOffset*value;
			}
			if (loseOffset <= -0.07) {
				return -0.07f;
			}else if(loseOffset >= -0.03) {
				return -0.035f;
			}
			return loseOffset;

		}else if (lossType.equals(WIN_OFFSET)) {
			float winOffset = SharePreferenceUtils.getFloatSP(mContext, lossType, 0.1f);
//			if (value==-1){
//				return winOffset;
//			}else{
//				winOffset = winOffset*value;
//			}
//			if (winOffset >= 10){
//				return 10;
//			}else if (winOffset <=3){
//				return 3;
//			}
			return winOffset;
		}
		return 0;
	}
	
	/**
	 *	返回语音播报的时间间隔，默认3分钟
	 * @param mContext
	 * @return
	 */
	public static int getVoiceDis(Context mContext) {
		return SharePreferenceUtils.getIntSP(mContext, VOICE_DIS, 3);
	}
	
	/**
	 * 设置语音播报间隔
	 * @param mContext
	 * @param voiceDis
	 */
	public static void setVoiceDis(Context mContext, int voiceDis){
		SharePreferenceUtils.setIntSP(mContext, VOICE_DIS, voiceDis);
	}
	
	public static void setLossOffSet(Context mContext,String lossType, float offset){
		SharePreferenceUtils.setFloatSP(mContext, lossType, offset);
	}
	
	public static float getBuyOffset(Context mContext,int fundId) {
		return getTradeOffset(mContext, fundId, TRADE_TYPE_BUY_OFFSET);
	}
	
	public static void setBuyOffset(Context mContext, int fundId,float offset){
		setTradeOffSet(mContext, fundId, TRADE_TYPE_BUY_OFFSET,offset);
	}
	
	public static float getSaleOffset(Context mContext,int fundId) {
		return getTradeOffset(mContext, fundId, TRADE_TYPE_SAILE_OFFSET);
	}
	
	public static void setSaleOffset(Context mContext, int fundId,float offset){
		setTradeOffSet(mContext, fundId, TRADE_TYPE_SAILE_OFFSET,offset);
	}
	
	public static void setIsTrackBuy(Context mContext, int fundId, boolean isTrack){
		SharePreferenceUtils.setBoolSP(mContext, fundId+"_"+TRADE_IS_BUY_TARCK, isTrack);
	}
	
	public static boolean getIsTrackBuy(Context mContext, int fundId) {
		return SharePreferenceUtils.getBoolSP(mContext, fundId+"_"+TRADE_IS_BUY_TARCK, false);
	}
	
	public static boolean getIsTrackSaile(Context mContext, int fundId) {
		return SharePreferenceUtils.getBoolSP(mContext, fundId+"_"+TRADE_IS_SAILE_TARCK, false);
	}
	
	public static float getTradeOffset(Context mContext,int fundId, String tradeTyp){
		return SharePreferenceUtils.getFloatSP(mContext, fundId+"_"+tradeTyp, .0f);
	}
	
	public static void setTradeOffSet(Context mContext,int fundId, String tradeTyp, float offset){
		SharePreferenceUtils.setFloatSP(mContext, fundId+"_"+tradeTyp, offset);
	}
	
	public static void setTradeMoney(Context mContext, int fundId,float money){
		SharePreferenceUtils.setFloatSP(mContext, fundId+"_"+TRADE_MONEY, money);
	}
	
	public static float getTradeMoney(Context mContext, int fundId){
		return SharePreferenceUtils.getFloatSP(mContext, fundId+"_"+TRADE_MONEY, .0f);
	}
	
	public static void setIsTrack(Context mContext, int fundId, String tradeTyp, boolean isTrack){
		SharePreferenceUtils.setBoolSP(mContext, fundId+"_"+tradeTyp, isTrack);
	}
	
	public static boolean getIsTrack(Context mContext, int fundId, String tradeTyp) {
		return SharePreferenceUtils.getBoolSP(mContext, fundId+"_"+tradeTyp, false);
	}
	
	public static void saveSpecificMode(Context mContext, OperateTrackSetModel model){
		setTradeOffSet(mContext,model.getFundid(), TRADE_TYPE_BUY_OFFSET, model.buyOffset);
		setTradeOffSet(mContext,model.getFundid(), TRADE_TYPE_SAILE_OFFSET, model.sailOffset);
		setTradeMoney(mContext, model.getFundid(), model.buyMoney);
		setIsTrack(mContext,    model.getFundid(), TRADE_IS_BUY_TARCK, model.isTrackBuy);
		setIsTrack(mContext, model.getFundid(), TRADE_IS_SAILE_TARCK, model.isTrackSaile);
	}
	
	/**
	 * 判断这个operatemode是否需要监控
	 * @param mode
	 * @return
	 */
	public static boolean getIsModeTrack(OperateModel mode) {
		// TODO Auto-generated method stub
		return false;
	}
	
	/**
	 * 获取仓位
	 * @param settingActivity
	 * @return
	 */
	public static float getPosition(Context mContext) {
		// TODO Auto-generated method stub
		return SharePreferenceUtils.getFloatSP(mContext, EXPTEC_POSITION, -1);
	}
	/**
	 * 设置仓位
	 * @param mContext
	 * @param value
	 */
	public static void setPosition(Context mContext,float value){
		SharePreferenceUtils.setFloatSP(mContext, EXPTEC_POSITION, value);
	}
	
}
